# encoding:utf8
import re


def match_ipv4(string_IPv4: str)->list:
    """
    匹配及校验ipv4地址是否合法，不合法则返回[]
    :param string_IPv4: 输入待校验的ipv4地址
    :return:
    """
    result = re.findall(
        r"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b", string_IPv4)
    return result

def match_ipv6(string_IPv6:str)->list:
    """
    匹配及校验ipv6地址是否合法，不合法则返回[]
    :param string_IPv6: 输入待校验的ipv6地址
    :return:
    """
    result = re.findall(r"(?<![:.\w])(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}(?![:.\w])", string_IPv6, re.I)
    return result


match_ipv4("127.0.0.1111")
match_ipv6("1050:0:0:0:5:600:300c:326b")
